﻿Public Class CategoriesOverview
    Inherits System.Web.UI.Page

    Public dbmanager As DBManager = New DBManager
    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        'Check if user is null
        If (Session("user") IsNot Nothing) Then
            'Retrieve userAcc details from session
            Dim userLoggedIn As userAcc = Session("user")
            'Check if user is admin, assign masterpage respectively
            If userLoggedIn.isAdmin Then
                Me.MasterPageFile = "~/MasterPage/Admin.Master"
            Else
                Me.MasterPageFile = "~/MasterPage/User.Master"
            End If
        Else
            'For anonymous users
            Me.MasterPageFile = "~/MasterPage/User.Master"
            'Enable this line to prevent anonymous users from entering this page
            ' Response.Redirect("~/Login.aspx")
        End If
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not IsPostBack) Then
            Dim counter As Integer = 1
            ''populate an array of category
            Dim Category() As String = {"Retail", "Fashion & Clothing ", "Beauty & Sports", "Home & Electronics", "Books & Music", "Entertainment", "Night Clubs", "Gaming", "Cinema", "Arts", "Museums", "Education", "Tuition Centre", "Enrichment Classes", "Health & Beauty", "Doctors", "Dentists", "Clinics", "Medical Spa / Spa", "Massage", "Makeup Artist", "Pets", "Pet Accessories", "Veterinarians"}
            '' parameter @category in getTopRatedBusinessByCategory is from the array
            '' for each item in the array
            '' populate the business name , image 
            For Each categoryItem As String In Category
                '    ' calling the arraylist from dbmanger 
                Dim imageArray As ArrayList = dbmanager.getTopRatedBusinessByCategory(categoryItem)
                Dim ImageButtonName = "ImageButton" + counter.ToString()
                'Dim image1 As ImageButton = sender.Form.FindControl(ImageButtonName)


                Dim image1 As ImageButton = ImageButton1.Parent.FindControl(ImageButtonName)
                Dim name As HyperLink = HyperLink1.Parent.FindControl("Hyperlink" + counter.ToString())
                '    'set image URl
                image1.ImageUrl = "IHttpHandler.ashx?id=" + imageArray(0)

                '    'get outlet id to redirect to 
                Dim outletID = dbmanager.getOutletImageID(imageArray(0))
                '    'get the name of the business 
                Dim businessName = dbmanager.getBusinessName(outletID)
                '    'get the name of the outlet
                Dim businessOutletName = dbmanager.getBusinessOutletName(outletID)

                name.Text = businessOutletName
                name.NavigateUrl = "OutletReview.aspx?id=" + outletID.ToString()
                '    ''Get business url to redirect to 
                image1.PostBackUrl = "OutletReview.aspx?id=" + outletID.ToString()
                '    ''add 1 to the count 
                counter = counter + 1

            Next

            lbRetail.PostBackUrl = "Categories.aspx?id=r"
            lbEntertainment.PostBackUrl = "Categories.aspx?id=e"
            lbEducation.PostBackUrl = "Categories.aspx?id=u"
            lbHealthBeauty.PostBackUrl = "Categories.aspx?id=h"
            lbPets.PostBackUrl = "Categories.aspx?id=p"
        End If
    End Sub

    Protected Sub PopulatingCategory()
        'Dim counter As Integer = 1
        ''populate an array of category
        'Dim Category() As String = {"Retail", "Fashion & Clothing ", "Beauty & Sports", "Home & Electronics", "Entertainment", "Night Clubs", "Gaming", "Cinema", "Arts", "Museums", "Education", "Tuition Centre", "Enrichment Classes", "Health & Beauty", "Doctors", "Dentists", "Hospitals", "Clinics", "Medical Spa / Spa", "Massage", "Makeup Artists", "Pets", " Pet Accessories", "Veterinarians"}
        '' parameter @category in getTopRatedBusinessByCategory is from the array
        '' for each item in the array
        '' populate the business name , image 
        'For Each categoryItem As String In Category
        '    ' calling the arraylist from dbmanger 
        '    Dim imageArray As ArrayList = dbmanager.getTopRatedBusinessByCategory(categoryItem)
        '    'Dim ImageButtonName = "ImageButton" + counter.ToString()
        '    'Dim image1 As ImageButton = Me.Form.FindControl(ImageButtonName)
        '    Dim image1 As ImageButton = Me.Form.FindControl("ImageButton1")
        '    'Me.Form.FindControl("ImageButtonName")
        '    'Dim name As HyperLink = Me.Form.FindControl("Hyperlink" + counter.ToString())
        '    'set image URl
        '    image1.ImageUrl = "IHttpHandler.ashx?id=" + imageArray(0)

        '    'get outlet id to redirect to 
        '    Dim outletID = dbmanager.getOutletImageID(imageArray(0))
        '    'get the name of the business 
        '    Dim businessName = dbmanager.getBusinessName(outletID)
        '    'get the name of the outlet
        '    Dim outletName = dbmanager.getOutletNameImageID(imageArray(0))

        '    'name.Text = String.Concat(businessName, "-", outletName)
        '    'name.NavigateUrl = "OutletReview.aspx?id=" + outletID.ToString()
        '    ''Get business url to redirect to 
        '    image1.PostBackUrl = "OutletReview.aspx?id=" + outletID.ToString()
        '    ''add 1 to the count 
        '    'counter = counter + 1
        '    Next
    End Sub
End Class